import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { Language } from "../../../../../extend/language/Language";
import { GTextFormat } from "../../../../common/GTextFormat";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { Cache } from "../../../cache/Cache";
import { MsgManager } from "../../../manager/MsgManager";
import { SDominionAuctionCity } from "../../../../../Message/Public/SDominionAuctionCity";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ProxyConfig } from "../../../resource/ProxyConfig";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { _auctionServices } from "../../../../../this/_auctionServices";
//class DomWarAuctionCellRender
    
    export  class DomWarAuctionCellRender extends GCellRenderer
    {
        constructor()
        {
            super();
            this._auctionServices = [];
            return;
        }

        protected /* override */ configUI(): void
        {
            super.configUI();
            this._isCreate = true;
            ObjCreate.createBg(0, 0, 190, 185, this);
            this._redCityBmp = new Object /* flash.display.Bitmap */();
            this.addChild(this._redCityBmp);
            this._redCityBmp.x = 15;
            this._redCityBmp.y = 15;
            ObjCreate.createBg(2, 2, 163, 23, this, ImagesConst.SelectedBg);
            this._titleBmp = new Object /* flash.display.Bitmap */();
            this.addChild(this._titleBmp);
            this._titleBmp.x = 43;
            this._titleBmp.y = 4;
            ObjCreate.createBg(2, 87, 163, 38, this, ImagesConst.SelectedBg);
            var loc1=GlobalStyle.textFormat5.clone();
            loc1.align = "center";
            this._citySerNameTxt = ObjCreate.createGTextField("", 1, 88, 190, 20, this, loc1);
            ObjCreate.createGTextField(Language.getString(90628) + ":", 33, 105, 100, 20, this, GlobalStyle.textFormat6);
            this._cityPowerTxt = ObjCreate.createGTextField("", 77, 105, 100, 20, this, GlobalStyle.textFormat6);
            this._cityPowerTxt.autoSize = "left";
            ObjCreate.createGTextField(Language.getString(90639), 62, 128, 100, 20, this, GlobalStyle.textFormat8);
            ObjCreate.createGTextField(Language.getString(90628) + ":", 33, 148, 105, 20, this, GlobalStyle.textFormat6);
            this._auctionSerPowerTxt = ObjCreate.createGTextField("", 75, 148, 100, 20, this, GlobalStyle.textFormat6);
            this._auctionSerTxt = ObjCreate.createGTextField("", 57, 163, 100, 20, this, GlobalStyle.textFormat6);
            this._auctionBtn = ObjCreate.createGButton("", 57, 187, 70, 25, this, "ArenaRedBtn");
            this._auctionBtn.drawNow();
            this._auctionBtn.setStyle("textFormat", new GTextFormat(null, null, 16776960));
            this.setBtnLabel();
            this._auctionBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onClickHandler);
            LoaderHelp.addResCallBack(ResFileConst.dominionWarBeacon, this.onloaded);
            return;
        }

        protected onClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this.info != null) 
            {
                if (this.isAuctionEnd()) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.ToOpenAuctionCityAlert, {"type": 2, "data": _auctionServices}));
                }
                else if (Cache.instance.dominionBea.isAuctioning()) 
                {
                    if (Cache.instance.country.isDominionPrivilege()) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.ToOpenAuctionCityAlert, {"type": 1, "x": this.info.x, "y": this.info.y}));
                    }
                    else 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(90659));
                    }
                }
                else 
                {
                    MsgManager.showRollTipsMsg(Language.getString(90666));
                }
            }
            return;
        }

        /* internal  */get info(): SDominionAuctionCity
        {
            return this._data as SDominionAuctionCity;
        }

        /* internal  */onloaded(): void
        {
            this._titleBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.DWBTxtImage_cityInfo);
            this._redCityBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.DwbCity_auctionCityIco);
            return;
        }

        /* internal  */isAuctionEnd(): Boolean
        {
            return Cache.instance.dominionBea.isAuctionEnd();
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            if (arg1 == null) 
            {
                return;
            }
            super.data = arg1;
            if (this.info) 
            {
                loc1 = ProxyConfig.instance.getProxyName(this.info.ownId.proxyId) + "-" + this.info.ownId.serverId;
                this._citySerNameTxt.text = this.info.name + "【" + loc1 + "】";
                loc1 = ProxyConfig.instance.getProxyName(this.info.auctionId.proxyId) + "-" + this.info.auctionId.serverId;
                this._auctionSerTxt.text = "[" + loc1 + "]";
                this._cityPowerTxt.text = this.info.combat.toString();
                this._auctionSerPowerTxt.text = this.info.auctionCombat.toString();
                this.updateAuctServer();
            }
            this.setBtnLabel(this.isAuctionEnd());
            return;
        }

        /* internal  */updateAuctServer(): void
        {
            var loc1=null;
            var loc3=null;
            var loc4=0;
            this._auctionServices = [];
            var loc2=[];
            var loc5=0;
            var loc6=this.info.auctionServiceMap;
            for(loc1 of loc6) 
            {
                loc2.push(loc1);
            }
            loc2.sortOn(["money", "serviceCombat"], Array.NUMERIC | Array.DESCENDING);
            loc4 = 0;
            while (loc4 < loc2.length) 
            {
                loc3 = {"rank": loc4 + 1, "info": loc2[loc4]};
                this._auctionServices.push(loc3);
                ++loc4;
            }
            return;
        }

        /* internal  */setBtnLabel(arg1: Boolean=false): void
        {
            if (arg1) 
            {
                this._auctionBtn.label = Language.getString(90648);
            }
            else 
            {
                this._auctionBtn.label = Language.getString(90633);
            }
            this._auctionBtn.drawNow();
            return;
        }

        /* internal */ /* var */_redCityBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_titleBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_auctionBtn: GButton;

        /* internal */ /* var */_citySerNameTxt: GTextFiled;

        /* internal */ /* var */_cityPowerTxt: GTextFiled;

        /* internal */ /* var */_auctionSerTxt: GTextFiled;

        /* internal */ /* var */_auctionSerPowerTxt: GTextFiled;

        /* internal */ /* var */_isCreate: Boolean;

        /* internal */ /* var */_auctionServices: Array<any>;
    }
